from .mongoApi import MongoConn
from .curl import *
import unicodedata

MonConn = MongoConn(log=False, db='apitools')


def delid(item):
    if isinstance(item, list):
        item = item[0]
    del item['_id']
    return item


def delid_list(item):
    result = []
    num = 0
    for num, i in enumerate(item):
        i.update({'_id': num + 1})
        result.append(i)
    return result


def uni_replace(str):
    result = re.sub(
        r"(\\u[a-zA-Z0-9]{4})",
        lambda x: x.group(1).encode("utf-8").decode("unicode-escape"),
        str,
    )
    result = re.sub(r"(\\r|\\n|\\t|\xa0|\\u[0-9]{4})", lambda x: "", result)
    result = unicodedata.normalize("NFKC", result)
    return result.strip()
